//
//  CZBaseViewController.swift
//  wuJunQianWeiBo
//
//  Created by apple on 15/12/16.
//  Copyright © 2015年 wujunqian. All rights reserved.
//

import UIKit

class CZBaseViewController: UITableViewController,CZVisitorViewDelegate {
    //用户是否登录标志
    var userLogin = false
    
    override func viewDidLoad() {
        super.viewDidLoad()
        userLogin ? super.loadView() : setupVisitorView()
    }
    //设置访客视图
    private func setupVisitorView()
    {
        view = CZVisitorView()
        view = visitorView
//        view.backgroundColor = UIColor.redColor()
        //设置代理
        visitorView.delegate = self
        
        //
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewRegisterClick")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewRegisterClick")
        
        if self is CZHomeController
        {
            visitorView.startRotationAnimation()
            //监听应用退到后台，用通知
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didEnterBackGround", name: UIApplicationDidEnterBackgroundNotification, object: nil)
            //监听应用进入到前台
            NSNotificationCenter.defaultCenter().addObserver(self, selector: "didBecomeActive", name: UIApplicationDidBecomeActiveNotification, object: nil)
        }
            //判断时哪个控制器
        else if self is CZMessageController
        {
            visitorView.setupInfo("visitordiscover_image_message", text: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
        }
        else if self is CZDiscoverController
        {
            visitorView.setupInfo("visitordiscover_image_message", text: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
        }
        else if self is CZProfileController
        {
            visitorView.setupInfo("visitordiscover_image_profile", text: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
    }
    
    //MARK: - 实现代理方法
    /**
    注册
    */
    func didRegisterButtonClick()
    {
        print(__FUNCTION__)
    }
    /**
     登录
     */
    func didLoginButtonClick()
    {
        let oauthVC = UINavigationController(rootViewController: CZOauthViewController())
        //弹出登录界面
        presentViewController(oauthVC, animated: true, completion: nil)
    }
    
    //MARK: - 监听方法
    func didEnterBackGround()
    {
        //调用暂停旋转的函数
        visitorView.pauseAnimation()
    }
    func didBecomeActive()
    {
        //调用恢复旋转的函数
        visitorView.resumeAnimation()
    }

    //懒加载visitorView
    lazy var visitorView: CZVisitorView = CZVisitorView()
    
}
